<?php

class Philosophe {
	private $disciples;
	private $nom;
	
	public function __construct($nom, $etuds=null) {
		$this->nom=$nom;
		
		$this->disciples=array();
		
		if (isset($etuds)) {
			if ( is_array($etuds) ) {
				$this->disciples=array_unique($etuds);
			} else {
				array_push($this->disciples, $etuds);
			}
		}
		
		foreach ($this->disciples as $etu) { $etu->setPhilosophe($this); }
	}
	
	public function __toString() {
		$str="Philosophe [ Nom: ".$this->nom."]";
		if (count($this->disciples) > 0) {
			$str.="\n\ts'occupe des disciples :";
			foreach ($this->disciples as $etu) { $str.="\n\t\t * ". $etu->getNom(); }
		} else { $str.="\n\tPas de disciple."; }
		$str.="\n";
		return $str;
	}
	
	public function addDisciple($etu, $propage=true) {
		if (!in_array($etu, $this->disciples)) array_push($this->disciples, $etu);
		if ($propage) foreach ($etu as $et) $et->setPhilosophe($this);
	}
	
	public function delDisciple($etu, $propage=true) {
		$this->disciples= array_diff($this->disciples, array($etu));
		if ($propage) $etu->delPhilosophe($this, false);
	}
	public function getNom() { return $this->nom; }
}
?>
